#include<bits/stdc++.h>
using namespace std;
int n,u,v,w;
long long sum,ans[800010];
struct lb{
	int to,val,pos;
};
vector<lb> edge[800010];
struct node{
	int s[21];
}son[800010],fa[800010],now;
node ad(node x,node y,int op){
	node res;
	memset(res.s,0,sizeof(res.s));
	for(int i=1;i<=20;i++)
		res.s[i]=x.s[i]+op*y.s[i];
	return res;
}
node clr(node x,int k){
	for(int i=20;i>k;i--)
		x.s[k]+=x.s[i],x.s[i]=0;
	return x;
}
long long tj(node x){
	long long res=0;
	for(int i=1;i<=20;i++)
		res+=1ll*x.s[i]*i;
	return res;
}
long long get(int x){
	long long res=0,sum=0;
	for(int i=20;i>=1;i--)
		res+=1ll*sum*son[x].s[i]*i,sum+=fa[x].s[i];
	sum=0;
	for(int i=20;i>=1;i--)
		res+=1ll*sum*fa[x].s[i]*i,sum+=son[x].s[i];
	for(int i=20;i>=1;i--)
		res+=1ll*i*fa[x].s[i]*son[x].s[i];
	return res;
}
void dfs1(int u,int f){
	son[u].s[20]=1;
	for(auto &i:edge[u])
		if(i.to!=f){
			dfs1(i.to,u);
			node now=son[i.to];
			now=clr(now,i.val),son[u]=ad(son[u],now,1);
		}
}
void dfs2(int u,int f,int pos){
	sum+=tj(fa[u])+tj(son[u])-20ll,ans[pos]=get(u);
	node now=fa[u];
	now.s[20]++;
	for(auto &i:edge[u])
		if(i.to!=f) now=ad(now,clr(son[i.to],i.val),1);
	for(auto &i:edge[u])
		if(i.to!=f){
			fa[i.to]=clr(ad(now,son[i.to],-1),i.val);
			dfs2(i.to,u,i.pos);
		}
}
int main(){
	freopen("tatooine.in","r",stdin);
	freopen("tatooine.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d%d",&u,&v,&w);
		edge[u].push_back({v,w,i}),edge[v].push_back({u,w,i});
	}
	dfs1(1,0),dfs2(1,0,0);
	for(int i=1;i<n;i++)
		printf("%lld\n",sum/2-ans[i]);
	return 0;
}
